/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// package org.apache.el.parser;
package com.gdevelop.gwtxp.rebind.el;


import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;


/**
 * @author Jacob Hookom [jacob@hookom.net]
 * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
 */
public class ArithmeticNode extends SimpleNode {

    /**
     * @param i
     */
    public ArithmeticNode(int i) {
        super(i);
    }

  //a: Trung
  public JClassType getReturnType(ELParserContext ctx) throws ELException, NotFoundException{
    JClassType type0 = this.children[0].getReturnType(ctx);
    JClassType type1 = this.children[1].getReturnType(ctx);
    if ((ctx.TYPE_Double.isAssignableFrom(type0)) || (ctx.TYPE_Double.isAssignableFrom(type1))){
      return ctx.TYPE_Double;
    }
    if ((ctx.TYPE_Float.isAssignableFrom(type0)) || (ctx.TYPE_Float.isAssignableFrom(type1))){
      return ctx.TYPE_Float;
    }
    if ((ctx.TYPE_Long.isAssignableFrom(type0)) || (ctx.TYPE_Long.isAssignableFrom(type1))){
      return ctx.TYPE_Long;
    }
    if ((ctx.TYPE_Integer.isAssignableFrom(type0)) || (ctx.TYPE_Integer.isAssignableFrom(type1))){
      return ctx.TYPE_Integer;
    }
    if ((ctx.TYPE_Short.isAssignableFrom(type0)) || (ctx.TYPE_Short.isAssignableFrom(type1))){
      return ctx.TYPE_Short;
    }
    if ((ctx.TYPE_Char.isAssignableFrom(type0)) || (ctx.TYPE_Char.isAssignableFrom(type1))){
      return ctx.TYPE_Char;
    }
    if ((ctx.TYPE_Byte.isAssignableFrom(type0)) || (ctx.TYPE_Byte.isAssignableFrom(type1))){
      return ctx.TYPE_Byte;
    }
    return ctx.TYPE_String;
  }
  public boolean isStaticValue(ELParserContext ctx) throws ELException, NotFoundException{
    return this.children[0].isStaticValue(ctx) && this.children[1].isStaticValue(ctx);
  }
  public String generateModelObservaleValue(ELParserContext ctx) throws ELException, NotFoundException {
    return generateComputedValue2(ctx, id, children[0], children[1], getReturnType(ctx));
  }
}
